package cn.yi.medicalsys.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;








import javax.servlet.http.HttpSession;

import cn.yi.medicalsys.pojo.Case;
import cn.yi.medicalsys.pojo.PageBean;
import cn.yi.medicalsys.service.CaseService;
import cn.yi.medicalsys.service.impl.CaseServiceImpl;

public class CaseServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// 创建病症业务处理对象
		CaseService cs =new CaseServiceImpl();
		// 获取总页数
		int totalCount = cs.findTotalPageCount(5);
		// 设置当前页数
		int pageNo = 1 ;
		// 获取参数传递的当前页数
		String temp = request.getParameter("pageno") ;
		// 判断参数是否为空
		if(temp != null && temp.length() > 0){
			//设置当前页数为参数值
			pageNo = Integer.valueOf(temp) ;
		}
		// 设置当前页数的最小值
		if(pageNo <= 0){
			pageNo =1 ;
		}
		// 设置当前页数的最大值
		if(pageNo > totalCount){
			pageNo = totalCount ;
		}
		// 获取 pageBean
		PageBean<Map<String, String>> bean = cs.findCaseByPageNo(pageNo, 3) ;
		// 创建 session 对象
		HttpSession session = request.getSession() ;
		// 保存 pageBean 到会话范围
		session.setAttribute("bean", bean);
		response.sendRedirect("hostory.jsp");
		out.flush();
		out.close();
	}
	public void init() throws ServletException {
		// Put your code here
	}

}
